package cn.com.yang.task;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadFactory;

import org.apache.commons.lang3.concurrent.BasicThreadFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;

/**
 * 总配置类
 * TODO
 * @author yangyijin
 * @since 2024年1月26日-下午3:57:51
 */
@Configuration
public class ScheduledConfig implements SchedulingConfigurer{

	@Override
	public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
		taskRegistrar.setScheduler(taskExecutorService());
		
	}
	@Bean(destroyMethod = "shutdown")
	public ExecutorService taskExecutorService() {
		ThreadFactory factory = new BasicThreadFactory.Builder()
				.namingPattern("my-scheduled-pool-%d").daemon(true).build();
		return new MyScheduledThreadPoolExcutor(Runtime.getRuntime().availableProcessors()*10, factory);
	}
	
}
